<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: callback.class.php 77081 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php


defined('PHPFOX') or exit('NO DICE!');


    class Follow_Service_Callback extends Phpfox_Service
    {
        public function getProfileMenu($aUser)
        {
            $aSubMenu = array();
            /*if ($aUser['user_id'] == Phpfox::getUserId() && $this->request()->get('req2') == 'follow')
            {
                $aSubMenu[] = array(
                'phrase' => Phpfox::getPhrase('follow.follower'),
                'url' => 'profile.follow.#follower',
                'total' => phpfox::getService('follow')->countFollower($aUser['user_id']),
                );
                $aSubMenu[] = array(
                'phrase' => Phpfox::getPhrase('follow.following'),
                'url' => 'profile.follow.#following',
                'total' => phpfox::getService('follow')->countFollowing($aUser['user_id']),
                );

            }
                $aMenus[] = array(
                'phrase' => Phpfox::getPhrase('follow.follow'),
                'url' => 'profile.follow',
                'sub_menu' => $aSubMenu,
                'icon' => 'feed/blog.png'
                );*/
            $aMenus[] = array(
            'phrase' => Phpfox::getPhrase('follow.follow'),
            'url' => 'profile.follow',
            'icon' => 'feed/blog.png');

            return $aMenus;
        }
        public function getProfileLink()
        {
            return 'profile.follow';
        }
        
        public function getNotification($aNotification)
        {
            $aRow = $this->database()->select('f.user_id, f.item_id, u.gender, u.full_name')
                ->from(Phpfox::getT('follow'),'f')                    
                ->join(Phpfox::getT('user'),'u','u.user_id = f.item_id')
                ->where('f.item_id = ' . (int) $aNotification['item_id'])
                ->execute('getSlaveRow');
            if(!isset($aRow['item_id'])) 
            {
                return false;
            }
            $sPhrase = Phpfox::getPhrase('follow.user_just_follow_you',array('full_name' => $aNotification['full_name']));
            return array(
                'link' => Phpfox::getLib('url')->permalink('profile', $aNotification['user_name']),
                'message' => $sPhrase,
                'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
            );
        }

        public function getNotificationWaiting($aNotification)
        {   
            $iUserId = $aNotification['user_id'];         
            $iNotiId = $aNotification['notification_id'];
            $aRow = $this->database()->select('fp.*,'.Phpfox::getUserField())
                ->from(Phpfox::getT('follow_pending'),'fp')                    
                ->join(Phpfox::getT('user'),'u','u.user_id = fp.item_id')
                ->where('fp.item_id = ' . (int) $aNotification['item_user_id'])
                ->execute('getSlaveRow');
            
            if(!isset($aRow['item_id']))
            {
                return false;
            }
            $sPhrase = Phpfox::getPhrase('follow.want_to_follow_you_new',array('full_name' => $aNotification['full_name'], 'user_id' => $iUserId, 'noti_id' => $iNotiId, 'type' => $aRow['type_id'],'item_id' => $aRow['item_id']));
            
            return array(
                'link' => Phpfox::getLib('url')->permalink('profile', $aNotification['user_name']),
                'message' => $sPhrase,
                'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
            );
        }
        public function getNotificationConfirm_Item($aNotification)
        {   
            $iUserId = $aNotification['user_id'];         
            $iNotiId = $aNotification['notification_id'];
            $aRow = $this->database()->select('f.*')
                ->from(Phpfox::getT('follow'),'f')                      
                ->where('f.id = '.(int)$aNotification['item_id'])
                ->execute('getSlaveRow');
            if(!isset($aRow['type_id']))
            {
                return false;
            }
            if($aRow['type_id'] == 'pages')
            {
                $aItem = Phpfox::getService('pages')->getPage($aRow['item_id']);    
            }
            else
            {   
                if(!Phpfox::hasCallback($aRow['type_id'], 'getActivityFeed'))
                {
                    return false;
                }
                $aParentModule = array(
                    'module_id' => $aRow['type_id'],
                    'item_id' => $aRow['item_id'],
                );
                $aItem = Phpfox::callback($aRow['type_id'] . '.getActivityFeed', $aParentModule, null, true);                    
            }
            $sGender = ($aNotification['gender'] == 1) ? Phpfox::getPhrase('follow.his'): Phpfox::getPhrase('follow.her');
            $sPhrase = Phpfox::getPhrase('follow.full_name_accepted_you_to_follow_gender_type_strong_title_strong',array('full_name' => $aNotification['full_name'], 'user_id' => $iUserId, 'gender' => $sGender, 'type' => $aRow['type_id'] , 'item_id' => $aRow['item_id'],'title' => Phpfox::getLib('parse.output')->shorten($aItem['title'], Phpfox::getParam('notification.total_notification_title_length'), '...')));
            
            return array(
                'link' => Phpfox::getLib('url')->permalink($aRow['type_id'], $aRow['item_id']),
                'message' => $sPhrase,
                'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
            );
        }
        public function getNotificationItem($aNotification)
        {
            $iUserId = $aNotification['user_id'];         
            $iNotiId = $aNotification['notification_id'];
            $aRow = $this->database()->select('f.*')
                ->from(Phpfox::getT('follow'),'f')                      
                ->where('f.id = '.(int)$aNotification['item_id'])
                ->execute('getSlaveRow');
                
            if(isset($aRow['user_id']) && $aRow['user_id'] == Phpfox::getUserId())
            {
                return false;
            }
            $aFollower = Phpfox::getService('user')->get($iUserId);
            if(!isset($aRow['type_id']))
            {
                return false;
            }
            if($aRow['type_id'] == 'pages')
            {
                $aItem = Phpfox::getService('pages')->getPage($aRow['item_id']);    
            }
            else
            {   
                if(!Phpfox::hasCallback($aRow['type_id'], 'getActivityFeed'))
                {
                    return false;
                }
                $aParentModule = array(
                    'module_id' => $aRow['type_id'],
                    'item_id' => $aRow['item_id'],
                );
                $aItem = Phpfox::callback($aRow['type_id'] . '.getActivityFeed', $aParentModule, null, true);                    
            }
            
            $sPhrase = Phpfox::getPhrase('follow.full_name_followed_your_type_strong_title_strong',array('full_name' => $aFollower['full_name'], 'type' => $aRow['type_id'],'title' => Phpfox::getLib('parse.output')->shorten($aItem['title'], Phpfox::getParam('notification.total_notification_title_length'), '...')));
            
            return array(
                'link' => Phpfox::getLib('url')->permalink($aRow['type_id'], $aRow['item_id']),
                'message' => $sPhrase,
                'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
            );
            
        }
        public function getNotificationWaiting_Item($aNotification)
        {   
            
            $iUserId = $aNotification['user_id'];         
            $iNotiId = $aNotification['notification_id'];
            $aRow = $this->database()->select('fp.user_id, fp.item_id, fp.type_id, u.gender, u.full_name')
                ->from(Phpfox::getT('follow_pending'),'fp')                    
                ->join(Phpfox::getT('user'),'u','u.user_id = fp.item_id')
                ->where('fp.item_id = ' . (int) $aNotification['item_user_id'])
                ->execute('getSlaveRow');
            if($aRow['type_id'] == 'pages')
            {
                $aItem = Phpfox::getService('pages')->getPage($aRow['item_id']);    
            }
            else
            {   
                if(!Phpfox::hasCallback($aRow['type_id'], 'getActivityFeed'))
                {
                    return false;
                }
                $aParentModule = array(
                    'module_id' => $aRow['type_id'],
                    'item_id' => $aRow['item_id'],
                );
                $aItem = Phpfox::callback($aRow['type_id'] . '.getActivityFeed', $aParentModule, null, true);                    
            }
            $sPhrase = Phpfox::getPhrase('follow.want_to_follow_your_page_title',array('full_name' => $aNotification['full_name'], 'user_id' => $iUserId, 'noti_id' => $iNotiId, 'type' => $aRow['type_id'] , 'item_id' => $aRow['item_id'],'title' => Phpfox::getLib('parse.output')->shorten($aItem['title'], Phpfox::getParam('notification.total_notification_title_length'), '...')));
            
            return array(
                'link' => Phpfox::getLib('url')->permalink('profile', $aNotification['user_name']),
                'message' => $sPhrase,
                'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
            );
        }
        
        public function getNotificationConfirm($aNotification)
        {
                
            $sPhrase = Phpfox::getPhrase('follow.full_name_accept_you_for_follow_gender',array(
                'full_name' => $aNotification['full_name'],
                'gender' => ($aNotification['gender'] == 1)? Phpfox::getPhrase('follow.him') : Phpfox::getPhrase('follow.her'),
            ));
            return array(
                'link' => Phpfox::getLib('url')->permalink('profile', $aNotification['user_name']),
                'message' => $sPhrase,
                'icon' => Phpfox::getLib('template')->getStyle('image', 'activity.png', 'blog')
            );
        }
        
        public function getProfileSettings()
        {
            return array(
                'follow.view_following_feed_profile' => array(
                    'phrase' => Phpfox::getPhrase('follow.view_your_following_feed_at_your_profile'),
                    'default' => '0',    
                    'no_user' => false,
                ),
                'follow.view_following_feed_follow' => array(
                    'phrase' => Phpfox::getPhrase('follow.view_your_following_feed_at_follow_index_page'),
                    'default' => '0',    
                    'no_user' => false,
                )
            );
        }
        public function getPageMenu($aPage)
        {   
            $aSubMenu = array();
            if ($this->request()->get('req3') == 'follow' || $this->request()->get('req2') == 'follow')
            { 
                $aSubMenu[] = array(
                    'phrase' => Phpfox::getPhrase('follow.follower'),
                    'url' => 'follower/'                
                );   
                if(Phpfox::getService('pages')->isAdmin($aPage))
                {
                    $aSubMenu[] = array(
                    'phrase' => Phpfox::getPhrase('follow.block'),
                    'url' => 'blocker/'                
                    );        
                    $aSubMenu[] = array(
                    'phrase' => Phpfox::getPhrase('follow.pending'),
                    'url' => 'pending/'     
                               
                     );    
                }
                $iPageId = $this->request()->get('req2');
                $oPage = Phpfox::getService('pages');
                $aPage = $oPage->getForView($iPageId);
                if(Phpfox::getService('pages')->isAdmin($aPage) || Phpfox::getService('follow')->isFollow(Phpfox::getUserId(), $iPageId, 'pages'))
                {
                    $aSubMenu[] = array(
                    'phrase' => Phpfox::getPhrase('follow.setting'),
                    'url' => 'setting/'                
                );        
                }
                
            }
            $aMenus[] = array
            (
                'phrase' => Phpfox::getPhrase('follow.follow'),
                'url' => Phpfox::getService('pages')->getUrl($aPage['page_id'], $aPage['title'], $aPage['vanity_url']) . 'follow/',
                'icon' => 'feed/blog.png',
                'landing' => 'follow',
                'sub_menu' => $aSubMenu,
            );
            return $aMenus; 
            
            
        }
        
        public function canViewPageSection($iPage)
        {
            return true;
        }
        
        public function getPageSubMenu($aPage)
        {
            return array();
        }    
    } 
?>
